const axios = require('axios');
const qs = require('qs')

// import qs from "qs";

class OpenAiRequest {
  constructor() {
    this.header = {
      "Authorization": "Bearer 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",
      "OpenAI-Organization": "org-yyN1wP8CuSzhRFI7sIx8Dkn0"
    }
    this.proxy = {
      protocol: 'http', // http还是https取决于你的代理
      host: "127.0.0.1",
      port: "7890",
    }
    this.commonHeader = {
      'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
      'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
      'Cache-Control': 'no-cache',
      'Connection': 'keep-alive',
      'Pragma': 'no-cache',
      'Upgrade-Insecure-Requests': '1',
      'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.5112.102 Safari/537.36 Edg/104.0.1293.70'
    }
    this.testUrl = 'https://api.openai.com/v1/files'
  }

  getData({method = "get", url = '', body}) {
    let config = {
      url,
      method,
      proxy: this.proxy,
      headers: {...this.header, ...this.commonHeader},
      data: body ? body : undefined
    }
    return axios(config)
  }

}

module.exports = {
  openAiRequest: new OpenAiRequest()
}
